<?php

namespace app\order\logic;

use app\common\library\Excel;
use app\common\library\RedissLock;
use app\common\service\TiktokPackageApiService;
use app\data\util\MqQueueName;
use app\order\logic\OrderListLogic;
use app\systems\logic\MqTaskPushLogic;
use think\facade\Config;
use Throwable;
use app\common\service\ConstantOrderService;
use app\order\model\Order as OrderModel;
use think\facade\Db;
use app\data\util\HttpUtil;

class OrderLogic
{
    protected $model = null;

    public function __construct()
    {
        $this->model = new OrderModel();
    }

    /**
     * @param $params
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     * @desc 订单列表
     * @author ligang
     */
    public function getOrdersList($params = [])
    {

        $orderId         = $params['order_id'] ?? '';
        $seller_sku      = $params['skus_info'] ?? '';
        $shipping_type   = $params['shipping_type'] ?? '';
        $status          = $params['status'] ?? '';
        $shop_id         = $params['shop_id'] ?? '';
        $brush_status    = $params['brush_status'] ?? '';
        $is_shipping_documents  = $params['is_shipping_documents'] ?? '';
        $tracking_number = $params['tracking_number'] ?? '';
        $createtime      = $params['createtime'] ?? '';
        $limit           = $params['limit'] ?? 10;
        $where = [];


        if ($orderId) {
            $order_ids = trim($orderId);
            $order_ids = array_filter(array_map('trim', explode("\n", $order_ids)));
            if (!empty($order_ids)) {
                $where[] = ['order.order_id', 'in', $order_ids];
            }
        }

        if($seller_sku){
            $orderIds = Db::name('order_info')
                ->where('seller_sku', 'like', '%' . $seller_sku . '%')
                ->column('order_id');
            $orderIds = array_unique($orderIds);
            if ($orderIds) {
                $where[] = ['order.order_id', 'in', $orderIds];
            }
        }

        if ($status) {
            if (trim($status) == 'AWAITING_COLLECTION_TIKTOK') {
                $where[] = ['order.shipping_type', '=', "TIKTOK"];
                $where[] = ['order.tracking_number', '<>', ""];
                $where[] = ['order.status', '=', "AWAITING_COLLECTION"];
                $where[] = ['order.send_status', '=', "0"];
            }else {
                if(trim($status) == 'AWAITING_SHIPMENT'){
                    $where[] = ['order.status', '=', $status];
                    $where[] = ['order.send_status', '<>', 1];
                }else{
                    $where[] = ['order.status', '=', $status];
                }
            }
        }
        if ($tracking_number){
            $where[] = ['order.tracking_number', 'like', '%' . $tracking_number . '%'];
        }

        if ($shipping_type){
            $where[] = ['order.shipping_type', '=', $shipping_type];
        }

        if ($brush_status){
            $where[] = ['order.brush_status', '=', $brush_status];
        }



        if ($createtime) {
            $createtimeArr = explode(',', $createtime);
            $where[] = ['order.createtime', '>=', strtotime($createtimeArr[0])];
            $where[] = ['order.createtime', '<=', strtotime($createtimeArr[1])];
        }


        if ($shop_id){
            $where[] = ['order.shop_id', '=', $shop_id];
        }

        if ($is_shipping_documents==1){
            $where[] = ['order.shipping_documents', '<>', ''];
        }


        if ($is_shipping_documents==2){
            $where[] = ['order.shipping_documents', '=', ''];
        }


        $field = [
                  'order.id','order.order_id','order.shop_id','order.createtime',
                  'order.updatetime','ship.warehouse_id','order.shipping_price',
                  'order.paid_time','order.delivery_time','order.fulfillment_type','order.brush_status',
                  'order.waybill_status','order.delivery_time','order.fulfillment_type','order.status',
                  'order.shipping_type','order.tracking_number','order.shipping_documents',
                   'appends.name','appends.phone_number'
                ];

        $res = Db::name('order')
            ->alias('order')
            ->leftJoin('ba_order_append appends', 'order.order_id = appends.order_id')
            ->leftJoin('ba_order_ship ship', 'order.order_id = ship.order_id')
            ->field($field)
            ->where($where)
            ->order('order.createtime DESC, order.id DESC')
            ->paginate($limit);

        $list      = $res->items()?:[];

        $shop_ids  = array_column($list,'shop_id');
        $shop_ids  = array_values(array_unique($shop_ids));

        $order_ids = array_column($list,'order_id');
        $order_ids = array_values(array_unique($order_ids));


        //批量获取店铺信息及sku数量信息;
        $shopInfos     = Db::name('shops')->whereIn('id',$shop_ids)->field('name,id')->select();
        $shopInfos     = objectToArray($shopInfos);
        $shopInfos_map = array_column($shopInfos,null,'id');

        //批量获取sku数量数据;
        $skuInfos     = Db::name('order_info')->whereIn('order_id',$order_ids)->field('seller_sku,order_id')->select();
        $skuInfos     = objectToArray($skuInfos);
        $skuInfos_map = self::get_sku_info($skuInfos);

        $info         = Config::get('Logisticskey.' . 'warehouse_arr_old');
        $brush_info   = Config::get('Logisticskey.' . 'brush_list');

        $where[] = ['order.shipping_price','<>',''];
        $total_info = Db::name('order')->alias('order')->where($where)->field('id,shipping_price')->select()->toArray();
        $total_shipping_price = array_sum(array_column($total_info, 'shipping_price'));

        $total_shipping_price = getRes($total_shipping_price);

        foreach($list as $k=>$v){
                $shop_names = $shopInfos_map[$v['shop_id']]??[];
                $sku_names  = $skuInfos_map[$v['order_id']]??[];
                $list[$k]['shop_name']     =  $shop_names['name']??'';
                $list[$k]['skus_info']     =  $sku_names ? implode(',',$sku_names):'';
                $list[$k]['brush_status']  =  $v['brush_status'] ? $brush_info[$v['brush_status']]:'';
                $list[$k]['warehouse_name']=  $v['warehouse_id'] ? $info[$v['warehouse_id']]:'';
        }

        $data = [
            'list'                => $list,
            'total'               => $res->total(),
            'total_shipping_price'=> $total_shipping_price,
            'total_shipping_num'  => count($total_info),
        ];
        return json(DefaultResponse(200, true, '获取成功', $data));
    }

    public function editOrder($project, $data)
    {
        if (!$data){
            return json(DefaultResponse(201, false, '参数不能为空!', null));
        }

        $result = false;
        $this->model->startTrans();
        try {
            $result = $project->save($data);
            $this->model->commit();
        } catch (Throwable $e) {
            $this->model->rollback();
            return json(DefaultResponse(201, false, $e->getMessage(), null));
        }
        if ($result !== false) {
            return json(DefaultResponse(200, true, '更新成功!', null));
        } else {
            return json(DefaultResponse(201, false, '更新失败!', null));
        }
    }

    /**
     * 刷单导入
     * @param $url
     * @return string
     */
    public function insertBrushOrder($url)
    {
        $data         = Excel::getExcelData('.' . '/' . $url);
        $excelData    = isset($data[0]) ? $data[0] : $data;
        if(!$excelData)   return json(DefaultResponse(201, false, '暂无数据!', null));
        //批量获取第一行数据;
        $orderIds    = array_column($excelData,'A');
        $orderIds    = array_filter($orderIds, function($value){
            // 过滤条件：只保留非空值
            return $value !== "" && $value !== null;
        });

        $existingOrderIds     = Db::name('order')->whereIn('order_id',$orderIds)->column('order_id');
        $existingShipOrderIds = Db::name('order_ship')->whereIn('order_id',$orderIds)->column('order_id');
        $num_error            = count($orderIds) - count($existingOrderIds);
        $num_success          = $num_error ? count($orderIds) - $num_error : count($orderIds);
        //批量获取订单的 shop_id
        $existingOrderInfo    = Db::name('order')->whereIn('order_id',$orderIds)->field('id,order_id,shop_id')->select();
        $existingOrderInfo    = objectToArray($existingOrderInfo);
        $existingOrder_map    = array_column($existingOrderInfo,null,'order_id');
        $toInsertOrderShip    = [];
        foreach ($orderIds as $orderId) {
            if (!in_array($orderId, $existingShipOrderIds)) {
                $order_info  = $existingOrder_map[$orderId]??[];
                $toInsertOrderShip[] = [
                    'order_id' => $orderId,
                    'shop_id'  => $order_info['shop_id']??'',
                    'status'   => 0
                ];
            }
        }

        try {
            Db::startTrans(); // 开启事务
            //批量更新刷单订单状态;
            Db::name('order')->where('order_id', 'in',$existingOrderIds)->update(['brush_status' => 'brush']);
            Db::name('order_ship')->insertAll($toInsertOrderShip);
            Db::commit(); // 提交事务
            return "导入完成：成功" . $num_success . "个，失败" . $num_error . "个";
        }
        catch (Exception $e) {
                Db::rollback(); // 回滚事务
            }
    }

    /**
     * 订单导出
     * @param $params
     * @return string
     */
    public function exportOrder($params = [])
    {
        $orderId         = $params['order_id'] ?? '';
        $seller_sku      = $params['skus_info'] ?? '';
        $shipping_type   = $params['shipping_type'] ?? '';
        $status          = $params['status'] ?? '';
        $shop_id         = $params['shop_id'] ?? '';
        $brush_status    = $params['brush_status'] ?? '';
        $tracking_number = $params['tracking_number'] ?? '';
        $createtime      = $params['createtime'] ?? '';
        $limit           = $params['limit'] ?? 10;
        $where = [];


        if ($orderId) {
            $order_ids = trim($orderId);
            $order_ids = array_filter(array_map('trim', explode("\n", $order_ids)));
            if (!empty($order_ids)) {
                $where[] = ['order.order_id', 'in', $order_ids];
            }
        }

        if($seller_sku){
            $orderIds = Db::name('order_info')
                ->where('seller_sku', 'like', '%' . $seller_sku . '%')
                ->column('order_id');
            $orderIds = array_unique($orderIds);
            if ($orderIds) {
                $where[] = ['order.order_id', 'in', $orderIds];
            }
        }

        if ($status) {
            if (trim($status) == 'AWAITING_COLLECTION_TIKTOK') {
                $where[] = ['order.shipping_type', '=', "TIKTOK"];
                $where[] = ['order.tracking_number', '<>', ""];
                $where[] = ['order.status', '=', "AWAITING_COLLECTION"];
                $where[] = ['order.send_status', '=', "0"];
            }else {
                $where[] = ['order.status', '=', $status];
            }
        }
        if ($tracking_number){
            $where[] = ['order.tracking_number', 'like', '%' . $tracking_number . '%'];
        }

        if ($shipping_type){
            $where[] = ['order.shipping_type', '=', $shipping_type];
        }

        if ($brush_status){
            $where[] = ['order.brush_status', '=', $brush_status];
        }



        if ($createtime) {
            $createtimeArr = explode(',', $createtime);
            $where[] = ['order.createtime', '>=', strtotime($createtimeArr[0])];
            $where[] = ['order.createtime', '<=', strtotime($createtimeArr[1])];
        }


        if ($shop_id){
            $where[] = ['order.shop_id', '=', $shop_id];
        }

        $field = [
            'order.id','order.order_id','order.shop_id','order.createtime',
            'order.updatetime','ship.warehouse_id','order.shipping_price',
            'order.paid_time','order.delivery_time','order.fulfillment_type','order.brush_status',
            'order.waybill_status','order.delivery_time','order.fulfillment_type','order.status',
            'order.shipping_type','order.tracking_number','order.shipping_documents',
            'appends.name','appends.phone_number'
        ];

        $res = Db::name('order')
            ->alias('order')
            ->leftJoin('ba_order_append appends', 'order.order_id = appends.order_id')
            ->leftJoin('ba_order_ship ship', 'order.order_id = ship.order_id')
            ->field($field)
            ->where($where)
            ->select();

        $list      = objectToArray($res);

        $shop_ids  = array_column($list,'shop_id');
        $shop_ids  = array_values(array_unique($shop_ids));

        $order_ids = array_column($list,'order_id');
        $order_ids = array_values(array_unique($order_ids));


        //批量获取店铺信息及sku数量信息;
        $shopInfos     = Db::name('shops')->whereIn('id',$shop_ids)->field('name,id')->select();
        $shopInfos     = objectToArray($shopInfos);
        $shopInfos_map = array_column($shopInfos,null,'id');

        //批量获取sku数量数据;
        $skuInfos     = Db::name('order_info')->whereIn('order_id',$order_ids)->field('seller_sku,order_id')->select();
        $skuInfos     = objectToArray($skuInfos);
        $skuInfos_map = self::get_sku_info($skuInfos);

        $info         = Config::get('Logisticskey.' . 'warehouse_arr');
        $brush_info   = Config::get('Logisticskey.' . 'brush_list');


        foreach($list as $k=>$v){
            $shop_names = $shopInfos_map[$v['shop_id']]??[];
            $sku_names  = $skuInfos_map[$v['order_id']]??[];
            $list[$k]['shop_name']     =  $shop_names['name']??'';
            $list[$k]['skus_info']     =  $sku_names ? implode(',',$sku_names):'';
            $list[$k]['brush_status']  =  $v['brush_status'] ? $brush_info[$v['brush_status']]:'';
            $list[$k]['warehouse_name']=  $v['warehouse_id'] ? $info[$v['warehouse_id']]:'';
        }


        $header[] = ['店铺', 'shop_name'];
        $header[] = ['订单号', 'order_id'];
        $header[] = ['SKU详情', 'skus_info'];
        $header[] = ['订单状态', 'status'];
        $header[] = ['跟踪号', 'tracking_number'];
        $header[] = ['客户姓名', 'name'];
        $header[] = ['客户电话', 'phone_number'];
        $header[] = ['仓库', 'warehouse_name'];
        $header[] = ['创建时间', 'createtime'];
        $fileName = "order_list_export_".time();
        return Excel::exportData($list, $header, $fileName, 'xlsx');
    }


    /**
     * @desc获取sku信息
     * @date  2024-03-28
     * @author  luckyXiong
     */
    public function get_sku_info($originalArray=[]){
        $newArray = [];
        foreach ($originalArray as $item) {
            $orderId = $item['order_id'];
            unset($item['order_id']);

            if (!isset($newArray[$orderId])) {
                $newArray[$orderId] = [];
            }

            $newArray[$orderId][] = $item['seller_sku'];
        }
        foreach ($newArray as &$values) {
            $values = array_combine(range(0, count($values) - 1), array_values($values));
        }
        return  $newArray;
    }



    /**
     * @desc    获取仓库ID信息
     * @date    2024-03-28
     * @author  luckyXiong  getGoldenByWarehouse
     */
    public function  getWareHouseList(){
        $info = Config::get('Logisticskey.' . 'warehouse_arr');
        $info = getLevel($info);
        $arr  = [];
        foreach($info as $v){
            $arr[] = [
                'warehouse_id'   => $v['key'],
                'warehouse_name' => $v['value'],
            ];
        }
        return json(DefaultResponse(200, true, '获取成功', $arr));
    }




    /**
     * @desc    获取仓库ID信息  //getWareHouseId
     * @date    2024-03-28  getBrushlist
     * @author  luckyXiong  getGoldenByWarehouse
     */
    public function getGoldenByWarehouse($data=[]){
        $warehouse_id   =  $data['warehouse_id']??'';
        $arr            =  [];
        if($warehouse_id ==3){ //金蚁仓库
              $info = Config::get('Logisticskey.' . 'golden_ant_channel');
              $info = getLevel($info);
              foreach($info as $v){
                  $arr[] = [
                      'golden_ant'      => $v['key'],
                      'golden_ant_name' => $v['value'],
                  ];
            }
        }
        return json(DefaultResponse(200, true, '获取成功', $arr));
    }



    /**
     * @desc    是否刷单接口
     * @date    2024-04-08  getBrushlist
     * @author  luckyXiong  getGoldenByWarehouse
     */
    public function getBrushlist(){
        $info = Config::get('Logisticskey.' . 'brush_list');
        $info = getLevel($info);
        foreach($info as $v){
            $arr[] = [
                'brush_status'         => $v['key'],
                'brush_status_value'   => $v['value'],
            ];
        }
        return json(DefaultResponse(200, true, '获取成功', ['options'=>$arr]));
    }


    /**
     * @desc    定时拉取订单信息消费方法  time_zone   shop_id  type
     * @date    2024-04-09
     * @author  luckyXiong
     */
    public function getOrderListConsumer($order){
        htmlLog(['order'=>$order],OPERATE_LOG . date('Ym') . '/getOrderListConsumer/' . date('Ymd') . '.txt');
        $order_id   = $order['id']??'';
        $type       = $order['type']??'';
        //查看订单列表数据;
        $order_info = Db::name('order')->where(['order_id' => $order_id])->find();
        //查看物流状态;
        $order_create_time   = $order['time_zone'] ? $order['create_time'] - $order['time_zone'] * 3600 : $order['create_time'];
        $order['createtime'] = $order_create_time;
        if($order_info){
            Db::name('order')->where(['order_id' => $order_id])->update(
                [
                    'shop_id'         => $order['shop_id'],
                    'fulfillment_type'=> $order['fulfillment_type'],
                    'status'          => $order['status'],
                    'tracking_number' => $order['tracking_number'],
                    'createtime'      => $order_create_time,
                ]
            );
        }else{
            if(in_array($type,[1,2])){
                //获取写入数据组装;
                $arr_info = (new OrderListLogic())->get_arr_info($order);
                try {
                    Db::startTrans(); // 开启事务
                    //批量写入数据;
                    Db::name('order')->insert($arr_info['order_arr']);
                    Db::name('order_info')->insertAll($arr_info['order_info_arr']);
                    Db::name('order_append')->insert($arr_info['order_append_arr']);
                    Db::commit(); // 提交事务
                    return  true;
                }
                catch (Exception $e) {
                    Db::rollback(); // 回滚事务
                    return [201, false, $e->getMessage(), null];
                }
            }
        }
        return true;
    }




    /**
     * @desc    定时更新订单信息消费方法
     * @date    2024-04-11
     * @author  luckyXiong
     */
    public function getOrderInfoConsumer($order){
        $shop      = Db::name('shops')->where("id", $order['shop_id'])->find();
        $tik_info  = Config::get('Logisticskey.' . 'TIKTOK');
        $baseUrl   = $tik_info['basic_url'];
        $path      = $tik_info['orders_info_path'];
        $sign      = $shop['app_secret'] . '' . $path . 'app_key' . $shop['app_key'] . 'ids' . $order['order_id'] . 'shop_cipher' . $shop['cipher'] . 'timestamp' . time() . '' . $shop['app_secret'];
        $sign      = hash_hmac('sha256', $sign, $shop['app_secret']);
        $url       = $baseUrl . $path . "?app_key=" . $shop['app_key'] . "&shop_cipher=" . $shop['cipher'] . "&sign=" . $sign . "&timestamp=" . time() . '&ids=' . $order['order_id'];
        $return    = HttpUtil::tikGetUrl($url, $shop['access_token']);
        if (!isset($return['data']['orders'][0]) || empty($return['data']['orders'][0])) return ['code' => 200, 'msg' => '暂无数据'];
        $orderinfo = $return['data']['orders'][0];

        if($shop['time_zone']){
            $orderinfo['createtime'] = $orderinfo['create_time'] - $shop['time_zone'] * 3600;
        }else{
            $orderinfo['createtime'] = $orderinfo['create_time'];
        }

        //获取更新数据组装;
        $arr_info  = (new OrderListLogic())->get_update_info($orderinfo);
        //批量写入数据;
        Db::name('order')->where('order_id',$order['order_id'])->update($arr_info['order_arr']);
        Db::name('order_append')->where('order_id',$order['order_id'])->update($arr_info['order_append_arr']);
        Db::commit(); // 提交事务
        return [200, true, '操作成功', null];
    }


    /**
     * @desc    批量更新面单的费用信息
     * @date    2024-04-25
     * @author  luckyXiong
     */
    public function syncShippingFees(){
        $where= [];
        $where[] = ['shipping_price','=',''];
        $where[] = ['shipping_type','=','TIKTOK'];
        $where[] = ['status','not in',['CANCELLED','UNPAID','ON_HOLD','COMPLETED']];
        $list = Db::name('order')->field('shop_id,order_id')->where($where)->select()->toArray();
        if(!$list)   return json(DefaultResponse(200, true, '暂无数据', ''));
        //数据推入队列处理;
         foreach($list as $v){
            MqTaskPushLogic::mq_task_push(
                '',
                MqQueueName::QUEUE_TIKTOK_FEE_ORDER_QUEUE,
                $v,
                false
            );
        }
        return json(DefaultResponse(200, true, '操作成功!'));
    }




    /**
     * @desc    批量更新面单的费用消费
     * @date    2024-04-26
     * @author  luckyXiong
     */
    public function shipping_fee_consumer($info){
        //并发处理;
        $redis_lock = new RedissLock();
        $key        = 'shipping_fee_consumer:'.time();
        $lock       = $redis_lock::lock($key, $redis_lock::UNBLOCK, 500);
        if (!$lock) {
            return ['code'=>201,'msg'=>'数据并发了'];
        }
        htmlLog(['data'=>$info],OPERATE_LOG . date('Ym') . '/shipping_fee_consumer/' . date('Ymd') . '.txt');
        //调用接口
        (new TiktokPackageApiService())->get_shipping_fee($info);
        $lock->unlock();
        return true;
    }




    /**
     * @desc    拉取订单更新数据写入
     * @date    2024-04-25
     * @author  luckyXiong
     */
    public function operateOrderProduce(){
        $list = Db::name('test_orderinfo')->field('order_id,shop_id')->select()->toArray();
        //数据推入队列处理;
        foreach($list as $v){
            MqTaskPushLogic::mq_task_push(
                '',
                MqQueueName::QUEUE_ORDER_INFO_OPERATE_QUEUE,
                $v,
                false
            );
        }
    }



    /**
     * @desc    批量更新面单的费用消费
     * @date    2024-04-26
     * @author  luckyXiong
     */
    public function operate_order_consumer($info){
        htmlLog(['data'=>$info],OPERATE_LOG . date('Ym') . '/operate_order_consumer/' . date('Ymd') . '.txt');
        //并发处理;
        $redis_lock = new RedissLock();
        $key        = 'operate_order_consumer:'.time();
        $lock       = $redis_lock::lock($key, $redis_lock::UNBLOCK, 500);
        if (!$lock) {
            return ['code'=>201,'msg'=>'数据并发了'];
        }
        htmlLog(['data'=>$info],OPERATE_LOG . date('Ym') . '/operate_order_consumer/' . date('Ymd') . '.txt');
        //调用接口
        (new TiktokPackageApiService())->get_operate_order($info);
        $lock->unlock();
        return true;
    }


    /**
     * @desc    获取access_token
     * @date    2024-05-05
     * @author  luckyXiong
     */
    public function getAccessToken($params=[]){
        htmlLog(['param'=>$params],OPERATE_LOG . date('Ym') . '/getAccessToken/' . date('Ymd') . '.txt');
        $app_key      = $params['app_key']??'';
        $access_token = $params['access_token']??'';
        $res = Db::name('shops')->where('app_key',$app_key)->update(['access_token'=>$access_token]);
        return  $res;
    }


    /**
     * @desc    定时更新用户基本信息
     * @date    2024-05-06
     * @author  luckyXiong
     */
    public function updateUserInfoProduce($params=[]){
        htmlLog(['param'=>$params],OPERATE_LOG . date('Ym') . '/updateUserInfoProduce/' . date('Ymd') . '.txt');
        $where   = [];
        $where[] = ['name','=',''];
        $order_info = Db::name('order')->where('status','=','ON_HOLD')->field('id,order_id')->select()->toArray();
        $order_ids  = array_column($order_info,'order_id');
        if($order_ids){
            $list = Db::name('order_append')->where($where)->whereNotIn('order_id',$order_ids)->field('shop_id,order_id')->select()->toArray();
        }else{
            $list = Db::name('order_append')->where($where)->field('shop_id,order_id')->select()->toArray();
        }
        if($list){
             foreach($list as $v){
                 MqTaskPushLogic::mq_task_push(
                     '',
                     MqQueueName::QUEUE_ORDER_INFO_UPDATE_QUEUE,
                     $v,
                     false
                 );
             }
        }
    }




    /**
     * @desc    定时更新用户基本信息
     * @date    2024-05-06
     * @author  luckyXiong
     */
    public function updateTrackingNumber($params=[]){
        htmlLog(['param'=>$params],OPERATE_LOG . date('Ym') . '/updateTrackingNumber/' . date('Ymd') . '.txt');
        $where   = [];
        $where[] = ['tracking_number','=',''];
        $where[] = ['status','in',['AWAITING_COLLECTION','AWAITING_SHIPMENT']];
        $where[] = ['shipping_documents','<>',''];
        $list    = Db::name('order')->where($where)->field('shop_id,order_id')->select();
        $list    = objectToArray($list);
        if(!$list)  return '暂无数据';
        foreach($list as $v){
                MqTaskPushLogic::mq_task_push(
                    '',
                    MqQueueName::QUEUE_ORDER_UPDATE_TRACK_NUMBER_QUEUE,
                    $v,
                    false
                );
        }

    }




}
